package com.jd.dict.config;

import java.io.*;
import java.util.Properties;

public class ConfigClass {
    public static final String IP;
    public static final String USERNAME;
    public static final String PASSWORD;
    public static final String DB_NAME;
    public static final String OUT_PATH;
    public static final String PORT;
    public static final String MODULE_NAME;

    static {
        String proFilePath = System.getProperty("user.dir") + "/config.properties";
        InputStream inputStream;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(proFilePath));
        } catch (FileNotFoundException e1) {
            throw new RuntimeException(e1);
        }

        Properties prop = new Properties();
        try {
            prop.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        IP = getStr( prop, "IP" );
        USERNAME = getStr( prop, "USERNAME" );
        PASSWORD = getStr( prop, "PASSWORD" );
        DB_NAME = getStr( prop, "DB_NAME" );
        OUT_PATH = getStr( prop, "OUT_PATH" );
        PORT = getStr( prop, "PORT" );
        MODULE_NAME = getStr(prop, "MODULE_NAME");
    }

    private static String getStr(Properties prop, String key) {
        String value = (String) prop.get(key);
        try {
            if (value != null) {
                value = value.trim();
                return new String(value.getBytes("ISO-8859-1"), "UTF-8");
            }
            return "";

        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
}
